<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019\3\2 0002
 * Time: 10:27
 */

namespace app\service;


use think\Db;

class indexService
{
    //查询出口设备名称
    public function system($where)
    {
        $system = Db::name('system')->where('type',2)->where($where)->select();
        return $system;
    }
    //获取停车场名称
    public function parkingName($parking_id)
    {

        $parkName = Db::name('parkinglotinfo')
						->where('out_parking_id',$parking_id)
						->value('parking_name');
        return $parkName;
    }
    //查询支付宝代扣总金额
    public function apiMoney($parking_id)
    {
     $alipay = Db::name('car_order')
					->where('out_parking_id',$parking_id)
					->where('pay_type','1')
					->sum('receipt_amount');
     return $alipay;
    }
    //查询支付宝扫码总金额
    public function ewmMoney($parking_id)
    {
        $Ewmpay = Db::name('car_order')
					->where('out_parking_id',$parking_id)
					->where(function ($query) {
						$query->where('pay_type', 2)->whereor('pay_type',3);
					})->sum('receipt_amount');
        return $Ewmpay;
    }
    //查询现金总金额
    public function Cash($parking_id)
    {
        $Cashpay = Db::name('car_order')
					->where('out_parking_id',$parking_id)
					->where('pay_type','7')
					->sum('receipt_amount');
        return $Cashpay;
    }
	
    //查询微信总金额
    public function wxMoney($parking_id)
    {
        $Wxpay = Db::name('car_order')
					->where('out_parking_id',$parking_id)
					->where(function ($query) {
						$query->where('pay_type', 4)->whereor('pay_type',5)->whereor('pay_type',6);
					})
					->sum('receipt_amount');
        return $Wxpay;
    }
	//查询优惠券总金额
    public function discount($parking_id)
    {
        $Wxpay = Db::name('car_order')
					->where('out_parking_id',$parking_id)
					->where('pay_type','10')
					->sum('discount_money');
        return $Wxpay;
    }
	//刷码总金额
    public function codeMoney($parking_id)
    {
        $codeMoney = Db::name('car_order')
						->where('out_parking_id',$parking_id)
						->where('pay_type','11')
						->sum('receipt_amount');
        return $codeMoney;
    }
    //根据条件查找小区数据
    public function communityList($where){
        return Db::name('parkinglotinfo')->where($where)->column('out_parking_id');
    }
	
	//根据登录账户信息查询账单信息
	public function orderWhereList($page,$where,$out_parking_id){
		$where['pay_type'] = array('neq',12);
        $sjwhere = $where;
		
        return Db::name('car_order')->where('out_parking_id','in',$out_parking_id)->where("status","2")->where($sjwhere)->order('id desc')->paginate(100, false, [
            'page'  =>  $page,
            'query' =>  $where
        ]);
    }
   
    //查询账单条数->where('pay_type','neq','12')
	public function orderWhereListNumber($where,$out_parking_id){
		$where['pay_type'] = array('neq',12);
        return Db::name('car_order')->where('out_parking_id','in',$out_parking_id)->where("status","2")->where($where)->count();
    }
    
	
	
	//查询支付宝代扣总金额
    public function apiMoney_orderinfo($parking_id,$where)
    {
     $alipay = Db::name('car_order')
				->where('out_parking_id','in',$parking_id)
				->where($where)
				
				->where('pay_type','1')
				
				->sum('receipt_amount');
     return $alipay;
    }
    //查询支付宝扫码总金额
    public function ewmMoney_orderinfo($parking_id,$where)
    {
        $Ewmpay = Db::name('car_order')
					->where('out_parking_id','in',$parking_id)
					->where($where)
					->where(function ($query) {
						$query->where('pay_type','2')->whereor('pay_type','3');
					})->sum('receipt_amount');
        return $Ewmpay;
    }
    //查询现金总金额
    public function Cash_orderinfo($parking_id,$where)
    {
        $Cashpay = Db::name('car_order')
					->where('out_parking_id','in',$parking_id)
					->where($where)
					->where('pay_type','7')
					
					->sum('receipt_amount');
        return $Cashpay;
    }
    //查询微信总金额
    public function wxMoney_orderinfo($parking_id,$where)
    {
        $Wxpay = Db::name('car_order')
					->where('out_parking_id','in',$parking_id)
					->where($where)
					->where(function ($query) {
						$query->where('pay_type','4')->whereor('pay_type','5')->whereor('pay_type','6');
					})
					
					->sum('receipt_amount');
        return $Wxpay;
    }
	//查询优惠券总金额
    public function discount_orderinfo($parking_id,$where)
    {
        $discount = Db::name('car_order')
					->where('out_parking_id','in',$parking_id)
					->where($where)
					->where('pay_type','10')
					
					->sum('discount_money');
        return $discount;
    }
	//查询刷码总金额
    public function codeMoney_orderinfo($parking_id,$where)
    {
        $codeMoney = Db::name('car_order')
						->where('out_parking_id','in',$parking_id)
						->where($where)->where('pay_type','11')
						
						->sum('receipt_amount');
        return $codeMoney;
    }
	//查询刷码总金额
    public function freeMoney_orderinfo($parking_id,$where)
    {
        $pay_money = Db::name('car_order')
						->where('out_parking_id','in',$parking_id)
						->where($where)->where('pay_type','14')
						
						->sum('pay_money');
        return $pay_money;
    }
	public function carvalueMoney_orderinfo($parking_id,$where)
	{
		$pay_money = Db::name('car_order')
						->where('out_parking_id','in',$parking_id)
						->where($where)->where('pay_type','15')
						
						->sum('pay_money');
        return $pay_money;
	}
}